package filters;

import Markers.Map;
import interfaces.IMap;

public class SubtractionFilter implements IFilter
{
	Map SubtractionMap;
	int LowLevel;
	SobelFilter SFilter;
		
		public SubtractionFilter(Map M,int level)
		{
			SFilter = new SobelFilter();
			LowLevel = level;
			SubtractionMap = M;
		}

		@Override
		public int ApplyFilter(int Px, int Py, IMap map) 
		{
			int CF = SFilter.ApplyFilter(Px, Py, map) & 255;
			int SF = SFilter.ApplyFilter(Px, Py, SubtractionMap) & 255;
			
			int cur = (int)(map.Get(Px,Py));
			int sub = (int)(SubtractionMap.Get(Px,Py));
			
			if(SF>LowLevel && CF>LowLevel)
				return cur;				
			
			if(cur-sub<0)
				return 0;
			return cur-sub;
		}
		
	}